import {Inject, Injectable} from '@angular/core';
import {APP_CONFIG} from '../../config/app.config';
import {AuthHttp} from '../../shared/auth.http';
import {Observable} from 'rxjs';
import {tap} from 'rxjs/internal/operators';
import {Coupon0624} from './coupon0624.model';

@Injectable()
export class PromotionService {
  private baseUrl: string;

  constructor(@Inject(APP_CONFIG) appConfig,
              private http: AuthHttp) {
    this.baseUrl = appConfig.endpoints.base;
    // this.baseUrl = 'http://localhost:8084/';
  }
  get0624Coupons(couponId: string): Observable<Coupon0624> {
    return this.http.get<Coupon0624>(this.baseUrl + 'be_prom/v2/coupon/' + couponId).pipe(
      tap( () => console.log('get coupons0624 successful...'),
        (err) => { console.error('get coupons0624 failed...'); console.error(err); })
    );
  }
  apply0624Coupons(couponId: string, phoneNumber: string): Observable<string> {
    return this.http.post<string>(this.baseUrl + 'be_prom/v2/coupon/apply/' + couponId + '/' + phoneNumber, null, null, 'text').pipe(
      tap( () => console.log('apply coupons0624 successful...'),
        (err) => { console.error('apply coupons0624 failed...'); console.error(err); } )
    );
  }
}
